//
//  TestSelectTableViewCell.m
//  AndCampus
//
//  Created by 史宵宵 on 2018/3/28.
//  Copyright © 2018年 史宵宵. All rights reserved.
//

#import "TestSelectTableViewCell.h"
@interface TestSelectTableViewCell()
@property (nonatomic,weak) UIButton *selectButton;
@end

@implementation TestSelectTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setTestSelectInfo:(TestSelectModel *)testSelectInfo{
    _testSelectInfo = testSelectInfo;
    if (self.testSelectType == KMoreAnswerTestSelectType) {
        self.testTitle.text = [NSString stringWithFormat:@"%ld/%ld %@",(long)self.num,(long)self.total,testSelectInfo.title];
        [self.firstButton setTitle:testSelectInfo.selectA forState:UIControlStateNormal];
        [self.secondButton setTitle:testSelectInfo.selectB forState:UIControlStateNormal];
    }else{
        self.testTitle.text = [NSString stringWithFormat:@"%ld/%ld %@",(long)self.num,(long)self.total,testSelectInfo.context];
        [self.firstButton setTitle:@"是" forState:UIControlStateNormal ];
        [self.secondButton setTitle:@"否" forState:UIControlStateNormal];
    }
    
    if ([testSelectInfo.answer isEqualToString:@"1"]) {
        self.firstButton.selected=YES;
        self.secondButton.selected=NO;
        self.selectButton = self.firstButton;
    }
    else if ([testSelectInfo.answer isEqualToString:@"0"]){
        self.firstButton.selected=NO;
        self.secondButton.selected=YES;
        self.selectButton = self.secondButton;
    }
    else{
        self.firstButton.selected=NO;
        self.secondButton.selected=NO;
        self.selectButton.selected = NO;
    }
//    if (self.testSelectType == KYESORNOTestSelectType) {
//        [self.firstButton setTitle:@"是" forState:UIControlStateNormal ];
//        [self.secondButton setTitle:@"否" forState:UIControlStateNormal];
//    }else if (self.testSelectType == KMoreAnswerTestSelectType) {
//
//    }
}
- (IBAction)firstSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    self.selectButton.selected = NO;
    button.selected = YES;
    self.selectButton = button;
    if (self.testSelectType == KYESORNOTestSelectType) {
        self.testSelectInfo.answer = @"1";
    }
    if (self.selectTestBlock) {
        self.selectTestBlock(@"1");
    }
}
- (IBAction)secondSelect:(id)sender {
    UIButton *button = (UIButton *)sender;
    self.selectButton.selected = NO;
    button.selected = YES;
    self.selectButton = button;
    if (self.testSelectType == KYESORNOTestSelectType) {
        self.testSelectInfo.answer = @"0";
    }
    if (self.selectTestBlock) {
        self.selectTestBlock(@"0");
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
